package com.example.baseadaptertest;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Spinner;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.example.baseadaptertest.adapter.PlantBaseAdapter;
import com.example.baseadaptertest.bean.Planet;

import java.util.List;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);
        Spinner spinner = findViewById(R.id.spinner);
        List<Planet> list = Planet.initPlant();
        PlantBaseAdapter plantBaseAdapter = new PlantBaseAdapter(this, list, R.layout.spin_item);
        spinner.setAdapter(plantBaseAdapter);
        spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                Planet planet = list.get(i);
                String msg = "当前点击的行星是:" + planet.getName() + " 点击的position是" + i + ",点击的l是" + l;
                Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {

            }
        });
    }
}